<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    // 案例1：求和数组内的平均值
    let arr  =  [100,200,300,400,500];
    let sum = 0;
    for(let i = 0;i < arr.length;i++){
        sum += arr[i];
    }
    let avg = sum/arr.length;
    console.log(sum,avg);

    //案例2：求数组[2,6,1,77,52,25,7]中的最大值
    let arr1 = [2,6,1,77,52,25,7];
    let max = arr1[0];

    for(let i = 0;i < arr1.length;i++){
        if(max < arr1[i]){
            max = arr1[i]
        }
    }
    console.log(max);

    //案例3：求数组[2,6,1,77,52,25,7]中的最小值
    let arr2 = [2,6,1,77,52,25,7];
    let min = arr1[0];

    for(let i = 0;i < arr2.length;i++){
        if(min > arr2[i]){
            min = arr2[i]
        }
    }
    console.log(min);

    //=>案例4：数组转换为分割字符串
    //将数组['red','green','blue','pink']转换为字符串，并且用|符号进行分割
    let arr3 = ['red','green','blue','pink'];
    let result = arr3.join('|');
    console.log(result);

    //=>案例5：新建一个数组，里面存放10个整数（1~10）
    let arr4 = [];
    for(let i = 0;i < 10;i++){
        arr4[i] = i + 1;  // 数组中的每一项 arr4[i]   i为（0-9）;
    }
    console.log(arr4);

    //案例6：将数组[2,0,6,1,77,0,52,0,25,7]中大于等于10的元素选出来，放入新数组
    let arr5 = [2,0,6,1,77,0,52,0,25,7];
    let newArr = []
    for(let i = 0;i < arr5.length;i++){
        if(arr5[i] > 10){
            newArr.push(arr5[i]);
        }
    }
    console.log(newArr);

    // 案例7：将数组[2, 0, 6, 1, 77, 0, 52, 0, 25, 7]中的0去掉后，形成一个不包含0的新数组
    let arr6 = [2, 0, 6, 1, 77, 0, 52, 0, 25, 7];
    let newArr1= [];
    for(let i in arr6){
        if(arr6[i] != 0){
            newArr1.push(arr6[i]);
        }
    }
    console.log(newArr1);

    //案例8：将数组['red','green','blue','pink','purple']的内容翻转过来存放
    let arr7 = ['red','green','blue','pink','purple'];
    arr7 = arr7.reverse();
    console.log(arr7);


    
</script>
</html>